<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/WEB-INF/jsppages/include/taglibs.jsp"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<title><%=system_name%> - 用户管理</title>
	<base href="<%=basePath%>" />
	<link type="image/x-icon" rel="shortcut icon" href="<%=basePath%>images/favicon.ico" />
 	<meta http-equiv="pragma" content="no-cache" />
 	<meta http-equiv="cache-control" content="no-cache" />
	<meta http-equiv="expires" content="0" />
	<link href="css/style.css" rel="stylesheet" type="text/css" />
	<link href="<%=basePath%>css/common.css" rel="stylesheet" type="text/css" />
	<link href="<%=basePath%>css/userlist.css" rel="stylesheet" type="text/css" />
	<script src="<%=basePath%>js/common.js" type="text/javascript"></script>
	<script type="text/javascript" src="js/pagebar_cn.js"></script>
	<script type="text/javascript" src="fram/engine.js" ></script>
	<script type="text/javascript" src="fram/util.js" ></script>
	<script type="text/javascript" src="fram/interface/userService.js"></script>
</head>

<body oncontextmenu='return false'>

	<!--top begin-->
	<%@include file="/WEB-INF/jsppages/admin/head.jsp"%>
	<!--top end-->


<div class="wrap100 content">

    <!--left begin-->
	<%@include file="/WEB-INF/jsppages/admin/left.jsp"%>
    <!--left end-->
    
    
    <!--right begin-->
	<div class="right">
        <div class="search">
                <form action="<%=basePath%>trade/userList" method="GET">
                <table width="100%" border="0" cellspacing="0" cellpadding="5">
                  <tr>
                    <td width="5%"><img src="images/marking1.gif" width="41" height="44" alt="marking" /></td>
                    <td width="8%">快速查询</td>
                    <td width="45%">请输入用户名称：<input type="text" name="name" value="${userSearchCond.name}" style="width:200px;" /></td></td>
                    <td width="11%">
                    <input type="submit" style="background:url(images/searchBtn.gif);width:116px;height:30px;border:0;margin:0;" value="" />
                    </td>
                    <td width="30%">
                    <jsp:useBean id="nowDate" class="java.util.Date"></jsp:useBean>
   					 现在是：${formatDate}<fmt:formatDate value="${nowDate}" type="both" dateStyle="full"/>
   					</td>
                    <td width="1%">&nbsp;</td>
                  </tr>
                </table>    
                </form>
        </div>
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td height="60"><h1>用户管理</h1></td>
              </tr>
            </table>
            <div class="rightContentTop">
              <div class="subMenu">
                <ul>
                  <li><a href="#" class="current">用户列表</a></li>
                </ul>
              </div>
   		    </div>
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td align="right"><span style="float:left;color:#666;">共找到<font color="red"> ${searchStat.totalCount} </font>条记录</span><a href="#"><!-- <img src="images/del.gif" width="90" height="31" alt="删除" /></a> --><a href="javascript:;" onclick="addUser()" style="font-weight:bold"><img src="images/add.gif" width="90" height="31" alt="添加人员" /></a></td>
              </tr>
            </table>
            <div class="rightContent1">
              <table width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr class="td">
                  <th width="4%" align="center" bgcolor="#f9f9f9"><input type="checkbox" name="checkbox4" id="checkbox4" /></th>
                  <th width="17%" align="center" bgcolor="#f9f9f9">姓名</th>
                  <th width="23%" align="center" bgcolor="#f9f9f9">部门</th>
                  <th width="16%" align="center" bgcolor="#f9f9f9">电话</th>
                  <th width="20%" align="center" bgcolor="#f9f9f9">权限</th>
                  <th width="20%" align="center" bgcolor="#f9f9f9">操作</th>
                </tr>
                <c:forEach var="user" items="${userList}">
                <tr>
                  <td align="center"><input type="checkbox" name="checkbox" id="checkbox" /></td>
                  <td align="center">${user.name}</td>
                  <td align="center">${user.dept.deptName}</td>
                  <td align="center">${user.telphone}</td>
                  <td>${user.userType.text}</td>
                  <td align="center">
                  	<a href="javascript:;" onclick="delUser('${user.id}')"><img src="images/del1.jpg" alt="删除" /></a>
                  	<a href="javascript:;" onclick="editUser('${user.id}')"><img src="images/modify.jpg" alt="修改" /></a>
                  	<a href="javascript:;" onclick="resetPass('${user.id}')">重设密码</a></td>
                </tr>
                </c:forEach>
				<c:if test="${empty userList}"><tr><td colspan="6" style="text-align:center">没有相关记录！</td></tr></c:if>
              </table>
            </div>
            <!-- 
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td><a href="zmateAdd.htm"><br />
                </a>　<a href="#"><img src="images/del.gif" width="90" height="31" alt="删除" /></a></td>
              </tr>
            </table> -->
            <script type="text/javascript">
		var pageControl = new wpagebar('pageControl');
		pageControl.argName = "pageIndex";
		pageControl.pageCount =${searchStat.pageCount};
		pageControl.load();		
  	</script>
          
    <div id="win_temp" style="display:none">
	<div id="winCon_1">
	<table class="tabView" style="margin-top:5px">
		<tr><th width="100">姓名：</th><td><input type="text" name="name0" id="name0" value=""/><input type="text" name="userId0" id="userId0" style="display:none"/></td></tr>
		<tr><th>账号：</th><td><input type="text" name="sign0" id="sign0"/><br/> <span style="color:blue">账号填写后不能修改，默认密码111111</span></td></tr>
		<tr><th>性别：</th><td><input type="radio" name="sex0" checked="checked"/>男 <input type="radio" name="sex0"/>女 </td></tr>
		<tr><th>电话：</th><td><input type="text" name="telphone0" id="telphone0" value=""/></td></tr>
		<tr><th>部门：</th><td>
			<select id="dept0">
			<c:forEach var="dept" items="${deptList}"><option value="${dept.id}">${dept.deptName}</option></c:forEach>
			</select>
		</td></tr>		
		<tr><th>权限：</th><td>
			<select id="type0">
			<c:forEach var="userType" items="${userType}">
			<option value="${userType.name}">${userType.text}</option>
			</c:forEach>
			</select>
		</tr>
		<tr><th>状态：</th><td><input type="radio" name="status0" checked="checked"/>启用 <input type="radio" name="status0"/>禁用</td></tr>
		<tr><td colspan="2" style="text-align:center;height:"><input type="button" value=" 提 交 " class="btn1" onclick="submitUser()"/></td></tr>
	</table>
	</div>
</div>  
    <script src="<%=basePath%>js/win.js" type="text/javascript"></script>
</div>
           
<script  type="text/javascript">
function addUser(){
	WIN.show('添加人员信息',$('winCon_1'),{height:350});
}
function editUser(id){
	WIN.show('修改人员信息',$('winCon_1'),{height:350});
	userService.getUserById(id,function(data){
		$('userId0').value=data.id;
		$('name0').value=data.name;
		if(data.sex){$N('sex0')[0].checked=true;}else{$N('sex0')[1].checked=true;}
		$('telphone0').value=data.telphone;
		$('dept0').value=data.dept.id;
		$('sign0').value=data.sign;
		$('sign0').disabled=true;
		$('type0').value=data.userType;
		if(data.status){$N('status0')[0].checked=true;}else{$N('status0')[1].checked=true;}		
	})
}
function delUser(id){
	if(confirm("删除用户，将导致用户无法登陆，确定删除 ？")){
		WIN.showpg();
		userService.delUserById(id,{
			callback:function(f){WIN.closepg();alert("删除成功");reload();},
			exceptionHandler:function(message){WIN.closepg();alert("删除失败，请重试");},
			errorHander:function(err){}
		})
	}
}
/*重设置用户密码*/
function resetPass(id){
	if(id==null) alert("请选择要操作用用户!");
	if(confirm("确定重设置用户密码 ？")){
		WIN.showpg();
		userService.resetPass(id,{
			callback:function(f){WIN.closepg();alert("操作成功，设置密码为111111 ");reload();},
			exceptionHandler:function(message){WIN.closepg();alert("操作失败，请重试");},
			errorHander:function(err){}
		})
	}
}

function submitUser(){
	var user={
			id:			$('userId0').value,
			name:		$('name0').value,
			sex:		$N('sex0')[0].checked,
			telphone:	$('telphone0').value,
			dept:		{id:$('dept0').value},
			sign:		$('sign0').value.trim(),
			userType:	$('type0').value,
			status:		$N('status0')[0].checked
	}
	
	if(''==user.sign){alert('账号不能为空');return;}
	if(''==user.dept.id){alert('请选择部门');return;}
	
	if(''==user.id){
		submitUser.user=user;		
		userService.hasSign(user.sign,{
			callback:function(f){if(f){alert('此账号已经存在，请更改');}else{submit(submitUser.user);}},
			exceptionHandler:function(message){WIN.closepg();alert(message);alert("操作失败，请重试");reload();},
			errorHander:function(err){}
		})
	}else{
		submit(user);
	}
}
function submit(user){
	WIN.close();
	WIN.showpg();
	userService.editUser(user,{
		callback:function(f){WIN.closepg();alert("操作成功");reload();},
		exceptionHandler:function(message){WIN.closepg();alert(message);alert("操作失败，请重试");},
		errorHander:function(err){}
	})
}

</script>
</body>
</html>
